package com.yunnuo.system.operlog.service.impl;

import com.yunnuo.system.operlog.dao.IOperLogDao;
import com.yunnuo.system.operlog.entity.OperLog;
import com.yunnuo.system.operlog.service.IOperLogService;
import com.yunnuo.system.comm.util.Empty;
import com.yunnuo.system.comm.util.page.TableDataInfo;
import com.yunnuo.system.users.entity.PageParams;
import org.hibernate.service.spi.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.*;
import java.util.List;

/**
 * @author 魏洪福（15064000912@163.com）
 * @create 2018-08-27-16:05
 */
@Service
public  class OperLogServiceImpl implements IOperLogService {

    @Autowired
    private IOperLogDao operLogDao;

    @Override
    public void addVO(OperLog vo) throws ServiceException {

        try{
          this.operLogDao.save(vo);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void updateVO(OperLog vo) throws ServiceException {

    }

    @Override
    public void delList(String[] ids) throws ServiceException {

    }

    @Override
    public void deleteVo(String id) throws ServiceException {

    }

    @Override
    public List<OperLog> findList() throws ServiceException {
        return null;
    }

    @Override
    public List<?> findList(OperLog vo, String other) throws ServiceException {
        return null;
    }

    @Override
    public OperLog findVO(String id) throws ServiceException {
        return null;
    }

    /**
     * 分页查询
     * @param pageParams
     * @param pageRequest
     * @return
     */
    @Override
    public TableDataInfo selectOperLogByPageParams(PageParams pageParams, PageRequest pageRequest) {
        TableDataInfo dataInfo=new TableDataInfo();
        Specification<OperLog> specification=new Specification<OperLog>() {
            @Override
            public Predicate toPredicate(Root<OperLog> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                Path<String> namePath=root.get("operName");
                String value=pageParams.getSearchValue();
                if (Empty.isNotEmpty(value)){
                    query.where(cb.like(namePath,"%"+value+"%"));
                }
                return null;
            }
        };
        Page<OperLog> operLogPages=operLogDao.findAll(specification,pageRequest);
        dataInfo.setRows(operLogPages.getContent());
        dataInfo.setTotal(operLogPages.getTotalElements());
        return dataInfo;

    }
}
